var express = require("express");
var router = express.Router();
const Result = require("../utils/result");
const sportsRecordService = require("../services/sportsRecordService");

router.post("/add", async function (req, res) {
    const sportsRecordArr = req.body.sportsRecord;
    await sportsRecordArr.forEach((item) => {
        sportsRecordService.add(item);
    });
    res.json(Result.success());
  });

router.get('/list',async function(req,res){
    const { userId, recordDate } = req.query;
  const record = await sportsRecordService.getRecord(userId, recordDate);
  res.json(Result.success(record));
})

router.get("/remove", async function (req, res) {
  const { id } = req.query;
  await sportsRecordService.remove(id);
  res.json(Result.success());
});

router.post("/update", async function (req, res) {
  const sportsRecord = req.body.sportsRecord;
  await sportsRecordService.update(sportsRecord);
  res.json(Result.success());
});

module.exports = router;